#include "EntProp.h"

#include <assert.h>

#include "types.h"

//--------------------------------------------------------------------------------------------------

EntProp::EntProp()
{
	colour.r = 255.0f;
	colour.g = 255.0f;
	colour.b = 255.0f;

	type = ENT_TYPE_PROP;

	fileName = "box";
}

EntProp::EntProp(ofxXmlSettings &xml) : Entity(xml)
{
	// Load colour values
	colour.r = xml.getValue("colour:r", 255.0f);
	colour.g = xml.getValue("colour:g", 255.0f);
	colour.b = xml.getValue("colour:b", 255.0f);

	type = ENT_TYPE_PROP;

	fileName = xml.getValue("model", "box");
}

void EntProp::customDraw()
{
	ofSetColor(colour);
	model.draw();
}

void EntProp::fixup()
{
	model.loadModel("models/" + fileName + ".3ds");
}

void EntProp::save(ofxXmlSettings &xml)
{
	// Standard attribute save ** IMPORTANT
	Entity::save(xml);

	xml.setValue("colour:r", colour.r);
	xml.setValue("colour:g", colour.g);
	xml.setValue("colour:b", colour.b);

	xml.setValue("model", fileName);
}

Entity* EntProp::copy()
{
	EntProp* newProp = new EntProp();

	entityStandardAttributesCopy(newProp, this);

	newProp->colour = this->colour;
	newProp->fileName = this->fileName;

	return newProp;
}

//--------------------------------------------------------------------------------------------------

Entity* entProp_create(ofxXmlSettings &xml)
{
	return new EntProp(xml);
}

//--------------------------------------------------------------------------------------------------
